<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#box{width:100px; height:100px; background:red; position:absolute;}
</style>
</head>

<body>
<script>
//document.onkeydown=function(ev){
//	var e=ev||event;
//	alert(e.keyCode)	
//};


//问题：当长按的时候会停顿 怎么解决？

document.onkeydown=function(e){
	
	var ev=e||event;
	var box=document.getElementById('box');
	if(ev.keyCode==37){
		box.style.left=box.offsetLeft-10+'px';	
	}else if(ev.keyCode==39){
		box.style.left=box.offsetLeft+10+'px';	
	}else if(ev.keyCode==38){
		box.style.top=box.offsetTop-10+'px';	
	}else if(ev.keyCode==40){
		box.style.top=box.offsetTop+10+'px';	
	};	
};
</script>
<div id="box"></div>
</body>
</html>
